#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e5 + 5;
const int S = 5e5 + 5;

int n, m;
string s[N];
int tr[S][26], ed[S], num;
void insert(string s, int id) {
  int p = 0;
  for (char c : s) {
    int ch = c - 'a';
    if (!tr[p][ch]) tr[p][ch] = ++num;
    p = tr[p][ch];
  }
  ed[p] = id;
}
int head[N];
int ver[N], Next[N], tot;
void add(int u, int v) {
  ++tot;
  ver[tot] = v;
  Next[tot] = head[u];
  head[u] = tot;
}
void dfs(int u, int fid) {
  int pid = fid;
  if (ed[u]) {
    add(fid, ed[u]);
    pid = ed[u];
  }
  rep(v, 0, 25) if (tr[u][v]) dfs(tr[u][v], pid);
}
int sz[N];
void dfs2(int u) {
  sz[u] = 1;
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    dfs2(v);
    sz[u] += sz[v];
  }
}
int pos[N], top;
ll ans;
bool cmp(int u, int v) { return sz[u] < sz[v]; }
void dfs3(int u, int fu) {
  pos[u] = ++top;
  ans += pos[u] - pos[fu];
  vector<int> ch;
  for (int i = head[u]; i; i = Next[i]) ch.push_back(ver[i]);
  sort(ch.begin(), ch.end(), cmp);
  for (int v : ch) dfs3(v, u);
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 1, n) cin >> s[i];
  // postfix -> prefix
  rep(i, 1, n) reverse(s[i].begin(), s[i].end());
  rep(i, 1, n) insert(s[i], i);
  dfs(0, 0);
  dfs2(0);
  dfs3(0, 0);
  cout << ans;
  return 0;
}